﻿package Welsy4.Connect.commands
{
	import mx.rpc.events.ResultEvent;
	import mx.rpc.IResponder;
	import mx.controls.Alert;
	
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.commands.SequenceCommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import Welsy4.Connect.business.MeetingDelegate;
	import Welsy4.Connect.events.*;
	import Welsy4.Connect.model.ConnectModel;
	import Welsy4.Connect.vo.HttpServiceHandler;
	
	
	public class ReportMyMeetingCommand extends SequenceCommand implements Command, IResponder
	{
		public function ReportMyMeetingCommand(){
			
		}
		override public function execute(event:CairngormEvent):void {
			ConnectModel.getInstance().addQueue("ReportMyMeeting.execute");
			this.nextEvent = ChainEvent(event).nextChainedEvent;
			
			var meetingDelegate:MeetingDelegate = new MeetingDelegate(this);
			meetingDelegate.reportMyMeeting();
		}
		
		public function result(event:Object):void {
		    ConnectModel.getInstance().addQueue("ReportMyMeeting.result");
			
			ConnectModel.getInstance().httpServiceHandler = new HttpServiceHandler();
			ConnectModel.getInstance().httpServiceHandler.setXML(event.result);
			
			
			this.executeNextCommand();
			
			ConnectModel.getInstance().myMeetings = ConnectModel.getInstance().httpServiceHandler.getMyMeetings();
			var stringfake:String = "";
			
			
			for (var i:int = 0; i < ConnectModel.getInstance().myMeetings.length; i++) {
				stringfake += ConnectModel.getInstance().myMeetings[i].getURL();
				stringfake += "\n" + ConnectModel.getInstance().myMeetings[i].sco_id;
				stringfake += "\n" + ConnectModel.getInstance().myMeetings[i].type;
				
			}
			
			Alert.show(ConnectModel.getInstance().myMeetings.length + " [" + stringfake + "]\n\nMeeting(yours)");
			
			 //Alert.show(ConnectModel.getInstance().httpServiceHandler.xml.meeting.@type + "\n\nMeeting(yours)");
			if (ConnectModel.getInstance().httpServiceHandler.getResultStatus() == ConnectModel.SESSION_OK) {
			    	
				    Alert.show(ConnectModel.getInstance().httpServiceHandler.xml + "\n\nMeeting(yours)");
					// dispatchevent user has been created --> a new command for a new era
					
			}
			
		}
		
		public function fault(event:Object):void {
			ConnectModel.getInstance().addQueue("ReportMyMeeting.fault");
		}
	}
	
}